;/*==================================================================================================
;  Description   Main
;  
;  20080905      Wim       Created
;==================================================================================================*/
HotKey, #1, Start
HotKey, #2, Stop
HotKey, #q, Quit
return


;/*==================================================================================================
;  Description
;  
;  20080905      Wim       Created
;==================================================================================================*/
Quit:
  ExitApp
  return


;/*==================================================================================================
;  Description
;  
;  20080905      Wim       Created
;==================================================================================================*/
Start:
  sleeper := 0
  outX := 0
  outY := 0
  state := 0
  running := 1
  
  SplashTextOn, 300, 50, Diva Script, Running script. windows-2 to stop.
  WinMove, Diva Script, , 0, 0

  loop
  {
    ;should select correct application first!
  
    if (state == 0)
    {
      ControlSetText, Static1, Running script. windows-2 to stop. `n '0: select live', Diva Script
      MouseClick, left,  1067,  250
      Sleep, 500
      state := 1
      sleeper := 0
    }
    else if (state == 1)
    {
      Sleep, 100
      ControlSetText, Static1, Running script. windows-2 to stop. `n '1: wait for completion (%sleeper%)', Diva Script
      sleeper++
      PixelSearch, outX, outY, 1024, 872, 1035, 879, 0xAE6607, 0, Fast RGB
      if (outX > 0)
      {
        state = 2
      }
      else if (sleeper > 1000)
      {
        state = 0
      }
    }
    else if (state == 2)
    {
      ControlSetText, Static1, Running script. windows-2 to stop. `n '2: select camera', Diva Script
      MouseClick, left,  1077,  456
      state = 3
      sleeper = 20
    }
    else if (state == 3)
    {
      ControlSetText, Static1, Running script. windows-2 to stop. `n '2: get live images (%sleeper%)', Diva Script
      Sleep, 100
      sleeper--
      if (sleeper <= 0)
      {
        state = 0
      }
    }
    else
    {
      state = 0;
    }
    
    if (running=0)
      break
  }
  SplashTextOff
  return


;/*==================================================================================================
;  Description
;  
;  20080905      Wim       Created
;==================================================================================================*/
Stop:
  running=0
  return


